
package org.zju.demo.shoppingdemo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.zju.demo.shoppingdemo.model.response.BaseResponse;


/**
 * Created by ZJDX on 2015/9/8.
 */

public abstract class CommonActivity extends Activity implements BaseActivityInterface{
    protected ImageView imageViewIndex = null;
    protected ImageView imageViewShopping = null;
    protected ImageView imageViewMyInfo = null;

    protected ImageViewIndexListener indexListener = new ImageViewIndexListener();
    protected ImageViewShoppingListener shoppingListener = new ImageViewShoppingListener();
    protected ImageViewMyInfoListener myInfoListener = new ImageViewMyInfoListener();

    protected TextView textViewTitle = null;

    class ImageViewIndexListener implements View.OnTouchListener {
        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if(event.getAction() == event.ACTION_DOWN) {
                Intent intent = new Intent();
                intent.setClass(CommonActivity.this, WelcomeActivity.class);
                startActivity(intent);
            }
            return false;
        }
    }

    class ImageViewShoppingListener implements View.OnTouchListener {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction() == event.ACTION_DOWN) {
                Intent intent = new Intent();
                intent.setClass(CommonActivity.this, CartActivity.class);
                startActivity(intent);
            }
            return false;
        }
    }

    class ImageViewMyInfoListener implements View.OnTouchListener {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == event.ACTION_DOWN) {
                Intent intent = new Intent();
                intent.setClass(CommonActivity.this, UserCenterActivity.class);
                startActivity(intent);
            }
            return false;
        }
    }
    public abstract void initBottomMenu();

    @Override
    public void onPreExecute() {
        // default do nothing
    }

    // corresponding to onPostExecute method in Async task
    @Override
    public void onResponseMessage(BaseResponse response) {
        // default do nothing
    }

    @Override
    public void onProgressUpdate(Object[] values) {
        // default do nothing
    }

    protected void doActivity(Class clazz) {
        doActivity(clazz, null);
    }

    protected void doActivity(Class clazz, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(this, clazz);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }
}